package api

import (
	"fmt"
	context "pd/server/app/pd/config"
	"pd/server/com"
	"pd/server/plugin/auth"

	"github.com/gin-gonic/gin"
)

// Start the REST API server using the configuration provided
func Start(conf *context.Config) {
	if conf.HttpServerMode() != "" {
		gin.SetMode(conf.HttpServerMode())
	} else if conf.Debug() == false && !com.IsLocal() {
		gin.SetMode(gin.ReleaseMode)
	}

	app := gin.New()

	app.Use(auth.Logger(), gin.Recovery())

	registerRoutes(app, conf)

	app.Run(fmt.Sprintf("%s:%d", conf.ApiHost(), conf.ApiPort()))
}
